﻿/*******************************************************************************
Copyright (c) 2011-2013, PKStudio
Copyright (c) 2011,      Zynga Inc.
Copyright (c) 2008-2010, Valentin Milea

http://pkstudio.org

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/

using System;
using System.Collections.Generic;
using System.Drawing;

namespace PKEngine
{
	/// <summary>
	/// Mouse infomation.
	/// </summary>
	public class PKMouseEvent
	{
		#region Public Properties
		public Point CurrentPos { get; private set; }
		public Point PrevPos { get; private set; }
		#endregion

		#region Initialization
		internal PKMouseEvent(int x, int y)
			: this(new Point(x, y))
		{
		}

		internal PKMouseEvent(Point point)
		{
			this.CurrentPos = point;
			this.PrevPos = point;
		}
		#endregion

		#region Public Methods
		public void SetPoint(int x, int y)
		{
			this.SetPoint(new Point(x, y));
		}

		public void SetPoint(Point point)
		{
			PrevPos = CurrentPos;
			CurrentPos = point;
		}
		#endregion
	}

	/// <summary>
	/// Interface for MouseResponder.
	/// </summary>
	public interface IPKMouseResponder
	{
		bool MouseDown(PKMouseEvent mouse);
		void MouseDrag(PKMouseEvent mouse);
		void MouseUp(PKMouseEvent mouse);
		bool MouseMove(PKMouseEvent mouse);
	}

	/// <summary>
	/// Mouse handler contains the delegate and priority.
	/// </summary>
	public class PKMouseHandler
	{
		#region Public Properties
		public IPKMouseResponder Target { get; set; }
		public int Priority { get; set; }
		public bool SwallowesEvents { get; set; }
		public PKMouseEvent ClaimedEvents { get; set; }
		#endregion

		#region Initialization
		public PKMouseHandler(IPKMouseResponder target)
			: this(target, 0, true)
		{
		}

		public PKMouseHandler(IPKMouseResponder target, int priority, bool swallowesEvents)
		{
			this.Target = target;
			this.Priority = priority;
			this.SwallowesEvents = swallowesEvents;
			this.ClaimedEvents = null;
		}
		#endregion
	}
}
